package com.example.jetpacktest.work

import android.content.Context
import android.util.Log
import androidx.work.CoroutineWorker
import androidx.work.WorkerParameters
import androidx.work.workDataOf
import kotlinx.coroutines.delay

/**
 * 可以展示工作进度
 */
class MyWork003(appContext: Context, params: WorkerParameters) : CoroutineWorker(appContext, params) {

    private val TAG: String = this.javaClass.simpleName


    override suspend fun doWork(): Result {
        Log.d(TAG, "MyWork003开始...............")
        setProgress(workDataOf(KEY_PROGRESS to 0))
        delay(DELAY)
        setProgress(workDataOf(KEY_PROGRESS to 50))
        delay(DELAY)
        setProgress(workDataOf(KEY_PROGRESS to 100))
        delay(DELAY)
        Log.d(TAG, "MyWork003结束...............")
        return Result.success()
    }


    companion object{
        const val KEY_PROGRESS: String = "KEY_PROGRESS"
        const val DELAY: Long = 10 * 1000
    }


}